<?php namespace Admin\Controller; 

use Hdphp\Controller\Controller;
use Admin\Model\ShopType;
//测试控制器
class ShopTypeController extends AuthController{
	//商品类型模型对象
	protected $db;
	//构造函数
	public function __init()
	{
		$this->db = new ShopType;
	}

    //商品类型列表
	public function index(){
		$data = $this->db->getAll();
		View::with('data',$data);
		View::make();
	}

	//添加商品类型
	public function add(){
		if(IS_POST)
		{
			if($this->db->store())
			{
				View::success('添加成功','index');
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			View::make();
		}
	}

	//修改商品类型
	public function edit(){
		if(IS_POST)
		{
			if($this->db->edit())
			{
				View::success('操作成功','index');
			}
			else
			{
				View::error($this->db->getError());
			}
		}
		else
		{
			$field = $this->db->one($_GET['id']);
			View::with('field',$field);
			View::make();
		}
	}
}















